#include "AccountUtils.hh"
#include <random>
#include <sstream>
#include <iomanip>

namespace minibank {

// === BankAccount struct: Rule of Three implementation ===
BankAccount::BankAccount() : accountId(""), type(AccountType::Checking), balance(0.0), transactions() {}

BankAccount::BankAccount(const BankAccount& other)
    : accountId(other.accountId), type(other.type), balance(other.balance), transactions(other.transactions) {}

BankAccount& BankAccount::operator=(const BankAccount& other) {
    if (this != &other) {
        accountId = other.accountId;
        type = other.type;
        balance = other.balance;
        transactions = other.transactions;
    }
    return *this;
}

BankAccount::~BankAccount() {
    // no dynamic memory used, safe to leave empty
}

std::string AccountUtils::generateAccountNumber(AccountType type) {
    std::ostringstream oss;
    oss << "62" << static_cast<int>(type);

    // Random number generation
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dist(0, 9999);

    int branch = dist(gen);
    int zzzz = dist(gen);
    int aaaa = dist(gen);

    oss << "-" << std::setw(4) << std::setfill('0') << branch
        << "-" << std::setw(4) << std::setfill('0') << zzzz
        << "-" << std::setw(4) << std::setfill('0') << aaaa;

    return oss.str();
}

} // namespace minibank